<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use JiaweiXS\WeApp\WeApp;
use think\Db;
use think\Request;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }
    public function test(){
        print_r(empty(""));
    }
    public function xcx(){
        $code=input('get.code','043NEpZP16f2M41SiwZP1sNuZP1NEpZJ');
        $weapp=new WeApp('wxe6abea40d49f5574','965b26500ad83a36e9bdbd9c39787b47','','/miniprogramcache/');
        $sk=$weapp->getSessionKey($code);
        //print_r($sk);
        $xcxarr=json_decode($sk,true);
        print_r($xcxarr);
        $user=Db::name('user');
        $data=[
             'open_id'=>$xcxarr['openid'],
            'session_key'=>$xcxarr['session_key'],
            'loginip'=>Request::instance()->ip(),
            'logintime'=>time(),
            'group_id'=>2,
        ];
        $user->data($data)->insert();
    }
}
